package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class FieldDemo01 {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        Class<Rectangle> rectangleClass = Rectangle.class;

        Constructor<Rectangle> constructor =
                rectangleClass.getDeclaredConstructor(int.class,int.class);

        constructor.setAccessible(true);
        Rectangle rectangle = constructor.newInstance(10,20);

        Field f1 = rectangleClass.getDeclaredField("length");
        f1.setAccessible(true);
        f1.set(rectangle,20);

        int tP = rectangle.getPerimeter();
        System.out.println("周長為："+tP);


    }
}
